<template>
  <van-nav-bar title="修改密码" left-text="返回" left-arrow @click="onClickLeft" />

  <van-cell-group inset>
    <van-field v-model="oldPassword" type="password" name="原密码" label="原密码" placeholder="请填写原密码"
      :rules="[{ required: true, message: '请填写原密码' }]" />
    <van-field v-model="newPassword" type="password" name="新密码" label="新密码" placeholder="请填写新密码"
      :rules="[{ required: true, message: '请填写新密码' }]" />
  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" @click="changePassword">
      提交
    </van-button>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import useUserStore from '@/store/user'


const oldPassword = ref('');
const newPassword = ref('');
const router = useRouter()
const userStore = useUserStore()



const onClickLeft = () => {
  router.go(-1)
}

const changePassword = () => {
  // 调用接口修改密码
  userStore.userChangePassword(
    userStore.userInfo.userid,
    oldPassword.value,
    newPassword.value
  )
}
</script>

<style scoped></style>
